package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ClassificationOfCulture;
import com.ruoyi.system.service.IClassificationOfCultureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BottomFlatInformationSheet;
import com.ruoyi.system.service.IBottomFlatInformationSheetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 海底滩涂信息Controller
 * 
 * @author ruoyi
 * @date 2024-05-14
 */
@RestController
@RequestMapping("/system/sheet")
@Api("海底滩涂信息接口")
public class BottomFlatInformationSheetController extends BaseController
{
    @Autowired
    private IBottomFlatInformationSheetService bottomFlatInformationSheetService;
    @Autowired
    private IClassificationOfCultureService classificationOfCultureService;

    /**
     * 查询海底滩涂信息列表
     */
    @ApiOperation("查询海底滩涂信息列表")
    @GetMapping("/list")
    public TableDataInfo list(BottomFlatInformationSheet bottomFlatInformationSheet)
    {
        startPage();
        List<BottomFlatInformationSheet> list = bottomFlatInformationSheetService.selectBottomFlatInformationSheetList(bottomFlatInformationSheet);
        list.forEach(item -> {
            ClassificationOfCulture classificationOfCulture = classificationOfCultureService.selectClassificationOfCultureById(item.getCulture());
            if (classificationOfCulture != null){
                item.setCultureDesc(classificationOfCultureService.selectClassificationOfCultureById(item.getCulture()).getName());
            }
        });
        return getDataTable(list);
    }

    /**
     * 导出海底滩涂信息列表
     */
    @ApiOperation("导出海底滩涂信息列表")
    @Log(title = "海底滩涂信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BottomFlatInformationSheet bottomFlatInformationSheet)
    {
        List<BottomFlatInformationSheet> list = bottomFlatInformationSheetService.selectBottomFlatInformationSheetList(bottomFlatInformationSheet);
        ExcelUtil<BottomFlatInformationSheet> util = new ExcelUtil<BottomFlatInformationSheet>(BottomFlatInformationSheet.class);
        util.exportExcel(response, list, "海底滩涂信息数据");
    }

    /**
     * 获取海底滩涂信息详细信息
     */
    @ApiOperation("获取海底滩涂信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bottomFlatInformationSheetService.selectBottomFlatInformationSheetById(id));
    }

    /**
     * 新增海底滩涂信息
     */
    @ApiOperation("新增海底滩涂信息")
    @Log(title = "海底滩涂信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BottomFlatInformationSheet bottomFlatInformationSheet)
    {
        return toAjax(bottomFlatInformationSheetService.insertBottomFlatInformationSheet(bottomFlatInformationSheet));
    }

    /**
     * 修改海底滩涂信息
     */
    @ApiOperation("修改海底滩涂信息")
    @Log(title = "海底滩涂信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BottomFlatInformationSheet bottomFlatInformationSheet)
    {
        return toAjax(bottomFlatInformationSheetService.updateBottomFlatInformationSheet(bottomFlatInformationSheet));
    }

    /**
     * 删除海底滩涂信息
     */
    @ApiOperation("删除海底滩涂信息")
    @Log(title = "海底滩涂信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bottomFlatInformationSheetService.deleteBottomFlatInformationSheetByIds(ids));
    }

}
